package com.tarry.trade.counter.entity;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Objects;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ResultResp<T> {

    private static final int SUCCESS = 200;
    private static final int ERROR = 500;

    private int code;
    private String msg;
    private T data;

    public static <T> ResultResp<T> success(){
        return new ResultResp(SUCCESS,null,null);
    }

    public static <T> ResultResp<T> success(T data){
        return new ResultResp(SUCCESS,null,data);
    }

    public static <T> ResultResp<T> error(){
        return new ResultResp(ERROR,null,null);
    }

    public static <T> ResultResp<T> error(String msg){
        return new ResultResp(ERROR,msg,null);
    }

    public static <T> ResultResp<T> error(String msg, T data){
        return new ResultResp(ERROR,msg,data);
    }

    public static Boolean isOk(int code){
        return Objects.equals(SUCCESS,code);
    }

    public static Boolean isError(int code){
        return !isOk(code);
    }
}
